<?php
include ('../../configs/cms.php');
include ('../includes/index.php');
include ('../includes/404.php');
include ('../classes/cPhotoAlbum.php');
include ('../classes/cImage.php');
$photoAlbum = new cPhotoAlbum ();
?>
<div style="margin: 0px; padding: 0px;">
	<?php
	if (!isset ($_GET ['albumname']))
	{
	    foreach ($photoAlbum -> getList () as $sAlbum)
	    {
		    echo '<a href="?albumname=' . rawurlencode ($sAlbum) . '">' . $sAlbum . '</a><br />';
	    }
	}
	else
	{
		if ($photoAlbum -> imageList ($_GET ['albumname']) === false)
		{
			echo 'Sorry, maar er zijn op dit moment geen afbeeldingen beschikbaar.';
		}
		else
		{
			foreach ($photoAlbum -> imageList ($_GET ['albumname']) as $sImage)
			{
				echo $sImage . '<br />';
			}
		}

		if ($_SERVER['REQUEST_METHOD'] == 'POST' && count ($_FILES) > 0)
		{
			for ($i = 1; $i <= 5; $i++)
			{
				if (!empty ($_FILES ['foto' . $i] ['tmp_name']))
				{
					move_uploaded_file ($_FILES ['foto' . $i] ['tmp_name'], '../../public/uploads/foto-album/albums/' . $_GET ['albumname'] . '/' . $_FILES ['foto' . $i] ['name'] . '___');
					$image = new cImage ('../../public/uploads/foto-album/albums/' . $_GET ['albumname'] . '/', $_FILES ['foto' . $i] ['name'] . '___');
					$image -> resizeImage (900);
					$image -> resizeImage (200);
					unlink ('../../public/uploads/foto-album/albums/' . $_GET ['albumname'] . '/' . $_FILES ['foto' . $i] ['name'] . '___');

				}
			}
		}
		else
		{
			echo '<form action="" method="post" enctype="multipart/form-data"><br />';
			for ($i = 1; $i <= 5; $i++)
			{
				echo '<label style="margin: 0px; float: left; width: 50px;">Foto ' . $i . ': </label><input accept="image/*" name="foto' . $i . '" type="file" /><br />';
			}
			echo '<br /><button type="submit">Submit</button>';
			echo '</form>';
		}
	}
	?>
	<br />
	<br />
	<?php
	echo '<a href="voegfotoalbumtoe.php">Maak album aan</a>';
	?>
</div>